package com.kgis.fm.business.management.service.impl;

import com.kgis.fm.business.access.service.FmEntityAccessService;
import com.kgis.fm.business.management.service.FmEntityManagementService;
import com.kgis.fm.business.mapadapter.service.MapAdapterManagementService;
import com.kgis.fm.business.model.Entity;
import com.kgis.fm.business.model.GeometryEntity;

public  class FmEntityManagementServiceImpl<T extends Entity> implements FmEntityManagementService<T>{
	@SuppressWarnings("unchecked")
	private FmEntityAccessService fmEntityAccessService;
	private MapAdapterManagementService mapAdapterManagementService;
	
	public MapAdapterManagementService getMapAdapterManagementService() {
		return mapAdapterManagementService;
	}

	public void setMapAdapterManagementService(MapAdapterManagementService mapAdapterManagementService) {
		this.mapAdapterManagementService = mapAdapterManagementService;
	}

	@Override
	public long sequence(String sequenceName) {
		return fmEntityAccessService.sequence(sequenceName);
	}

	@SuppressWarnings("unchecked")
	public T create(T entity) {
		T model=(T)fmEntityAccessService.create(entity);
		return  model;
	}

	@Override
	public T update(T entity) {
		return null;
	}
	
	@SuppressWarnings("unchecked")
	public FmEntityAccessService getFmEntityAccessService() {
		return fmEntityAccessService;
	}
	@SuppressWarnings("unchecked")
	public void setFmEntityAccessService(FmEntityAccessService fmEntityAccessService) {
		this.fmEntityAccessService = fmEntityAccessService;
	}

	@Override
	public T createGeometryEntity(T entity) {
		try {
			mapAdapterManagementService.createSpatial((GeometryEntity)entity);
		} catch (Exception e) {
			return null;
		}
		return entity;
	}
}
